Share via


WebApplicationFactory<TEntryPoint> Class

Definition

Factory for bootstrapping an application in memory for functional end to end tests.

generic <typename TEntryPoint>
 where TEntryPoint : classpublic ref class WebApplicationFactory : IDisposable
public class WebApplicationFactory<TEntryPoint> : IDisposable where TEntryPoint : class
public class WebApplicationFactory<TEntryPoint> : IAsyncDisposable, IDisposable where TEntryPoint : class
type WebApplicationFactory<'EntryPoint (requires 'EntryPoint : null)> = class
    interface IDisposable
type WebApplicationFactory<'EntryPoint (requires 'EntryPoint : null)> = class
    interface IDisposable
    interface IAsyncDisposable
Public Class WebApplicationFactory(Of TEntryPoint)
Implements IDisposable
Public Class WebApplicationFactory(Of TEntryPoint)
Implements IAsyncDisposable, IDisposable

Type Parameters

TEntryPoint

A type in the entry point assembly of the application. Typically the Startup or Program classes can be used.

Inheritance
WebApplicationFactory<TEntryPoint>
Implements

Constructors

WebApplicationFactory<TEntryPoint>()

Creates an instance of WebApplicationFactory<TEntryPoint>. This factory can be used to create a TestServer instance using the MVC application defined by TEntryPoint and one or more HttpClient instances used to send HttpRequestMessage to the TestServer. The WebApplicationFactory<TEntryPoint> will find the entry point class of TEntryPoint assembly and initialize the application by calling IWebHostBuilder CreateWebHostBuilder(string [] args) on TEntryPoint.

This constructor will infer the application content root path by searching for a WebApplicationFactoryContentRootAttribute on the assembly containing the functional tests with a key equal to the TEntryPoint assembly FullName. In case an attribute with the right key can't be found, WebApplicationFactory<TEntryPoint> will fall back to searching for a solution file (*.sln) and then appending TEntryPoint assembly name to the solution directory. The application root directory will be used to discover views and content files.

The application assemblies will be loaded from the dependency context of the assembly containing TEntryPoint. This means that project dependencies of the assembly containing TEntryPoint will be loaded as application assemblies.

Properties

ClientOptions

Gets the WebApplicationFactoryClientOptions used by CreateClient().

Factories

Gets the IReadOnlyList<T> of factories created from this factory by further customizing the IWebHostBuilder when calling WithWebHostBuilder(Action<IWebHostBuilder>).

Server

Gets the TestServer created by this WebApplicationFactory<TEntryPoint>.

Services

Gets the IServiceProvider created by the server associated with this WebApplicationFactory<TEntryPoint>.

Methods

ConfigureClient(HttpClient)

Configures HttpClient instances created by this WebApplicationFactory<TEntryPoint>.

ConfigureWebHost(IWebHostBuilder)

Gives a fixture an opportunity to configure the application before it gets built.

CreateClient()

Creates an instance of HttpClient that automatically follows redirects and handles cookies.

CreateClient(WebApplicationFactoryClientOptions)

Creates an instance of HttpClient that automatically follows redirects and handles cookies.

CreateDefaultClient(DelegatingHandler[])

Creates a new instance of an HttpClient that can be used to send HttpRequestMessage to the server. The base address of the HttpClient instance will be set to http://localhost.

CreateDefaultClient(Uri, DelegatingHandler[])

Creates a new instance of an HttpClient that can be used to send HttpRequestMessage to the server.

CreateHost(IHostBuilder)

Creates the IHost with the bootstrapped application in builder. This is only called for applications using IHostBuilder. Applications based on IWebHostBuilder will use CreateServer(IWebHostBuilder) instead.

CreateHostBuilder()

Creates a IHostBuilder used to set up TestServer.

CreateServer(IWebHostBuilder)

Creates the TestServer with the bootstrapped application in builder. This is only called for applications using IWebHostBuilder. Applications based on IHostBuilder will use CreateHost(IHostBuilder) instead.

CreateWebHostBuilder()

Creates a IWebHostBuilder used to set up TestServer.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Dispose(Boolean)

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

Finalize()

Finalizes an instance of the WebApplicationFactory<TEntryPoint> class.

GetTestAssemblies()

Gets the assemblies containing the functional tests. The WebApplicationFactoryContentRootAttribute applied to these assemblies defines the content root to use for the given TEntryPoint.

WithWebHostBuilder(Action<IWebHostBuilder>)

Creates a new WebApplicationFactory<TEntryPoint> with a IWebHostBuilder that is further customized by configuration.

Applies to